package com.zjs.jsp.fdservice.service.mongodb;

import com.mongodb.BasicDBObject;
import com.zjs.jsp.domain.jsp.Jsp_Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Component;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 拓展mong
 *
 * @author 李文
 * @create 2017-09-01 17:25
 **/
@Component
public class JspTaskExpand
{
    @Autowired
    private MongoTemplate mongoTemplate;


    /**
     * 初次下发订单更新
     *
     * @param tk
     */
    public void update(String tk, Date date) {
        mongoTemplate.upsert(new Query(Criteria.where("tk").is(tk)),
                new Update().set("Xfzt", 1).set("ud", date), Jsp_Task.class);
    }


    /**
     * 获取存在首次为下发的任务包的 厅点编码
     *
     * @return
     */
    public List<String> getPk() {


        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.MONTH, -1);
        BasicDBObject query = new BasicDBObject();
        query.put("date", new BasicDBObject("$gte", calendar.getTime()));
        query.put("xfzt", 0);
        List<String> sto = mongoTemplate.getDb().getCollection("jsp_Task").distinct("pk", query);
        return sto;
    }

}
